package com.wc.AlgoOJ_train.train2_DP训练.c7_状压DP.DP0602_旅行商;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/21 20:01
 * @description http://43.138.190.70:8888/p/DP0602
 */
public class Main {
    /**
     * 思路：f[i][j] 表示当前状态为 i 最后到达 j 的最短路
     *      状态转移 f[i][j] = Math.min(f[i][j], f[i - (1 << j)][k] + a[k][j])
     *      j 表示中间城市 k = 1 << j
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 18, M = 1 << N;
    static int[][] f = new int[M][N];
    static int[][] a = new int[N][N];
    static int INF = 0x3f3f3f3f;
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < 1 << n; i++) {
            Arrays.fill(f[i], INF);
        }
        f[1][0] = 0;
        for (int i = 1; i < 1 << n; i += 2) {
            for (int j = 0; j < n; j++) {
                if ((i >> j & 1) == 1) {
                    for (int k = 0; k < n; k++) {
                        if ((i - (1 << j) >> k & 1) == 1) {
                            f[i][j] = Math.min(f[i][j], f[i - (1 << j)][k] + a[k][j]);
                        }
                    }
                }
            }
        }
        int res = INF;
        for (int i = 0; i < n; i++) res = Math.min(res, f[(1 << n) - 1][i] + a[i][0]);
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
